package com.eternalrights.controller;

import com.eternalrights.anno.Log;
import com.eternalrights.pojo.Emp;
import com.eternalrights.pojo.EmpQueryResult;
import com.eternalrights.pojo.PageResult;
import com.eternalrights.pojo.Result;
import com.eternalrights.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/emps")
@Slf4j
public class EmpController {

    @Autowired
    private EmpService empService;

    @GetMapping
    public Result page(EmpQueryResult empQueryResult){
       log.info("分页查询，start:{},pageSize:{},name:{},gender:{},begin:{},end:{}",empQueryResult);
        PageResult<Emp> pageResult  = empService.page(empQueryResult);
        return Result.success(pageResult);
    }

    @PostMapping
    @Log
    public Result save(@RequestBody Emp emp){
        log.info("保存员工，员工信息：{}",emp);
        empService.save(emp);
        return Result.success();
    }

    @DeleteMapping
    @Log
    public Result delete(@RequestParam List<Integer> ids){
        log.info("批量删除员工，员工id：{}",ids);
        empService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询指定员工所有信息: {}",id);
        Emp emp = empService.getInfo(id);
        return Result.success(emp);
    }

    @PutMapping
    @Log
    public Result update(@RequestBody Emp emp){
        log.info("修改员工信息：{}",emp);
        empService.update(emp);
        return Result.success();
    }

    @GetMapping("/list")
    public Result findEmp(){
        return Result.success(empService.findEmp());
    }
}
